<?php
$entity = $vars['entity'];
$minutes = $vars['minutes'];

$timetable = $entity->getTimetables();
?>
<script type="text/javascript">
/* Timetable mini-manager TODO: Move to a separated file */
var hiddenElements;
function addLine()
{
	//Get the hidden elements
	var aux = $('#timetable-rows').find('.hidden');
	var element = aux[0];
	
	$(element).detach();
	$(element).removeClass('hidden');
	$('#timetable-rows').append(element);
}
function removeLine(button)
{
	$(button).parent().find('input').attr('value', '');
	$(button).parent().addClass('hidden');
}
</script>

<style>
.hidden
{
	display:none;
}
</style>
<div id="timetable-info" class="form-section-body" style="display: none;">
	<div class="elgg-module elgg-module-featured">
		<div class="elgg-head">
			<h3>Informacion sobre esta seccion</h3>
		</div>
		<div class="elgg-body" style="display:none;">
			<ul>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
				<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
			</ul>
		</div>
	</div>
	
	<a href="javascript:addLine();" class="elgg-button elgg-button-special">Agregar jornada</a>
	<br><br>
	<div id="timetable-rows">
		<?php for($i = 0; $i < 30; $i++): ?>
			
			<?php if(is_array($timetable[$i])):?>
			<div class="timetable-row">
			<? else: ?>
			<div class="timetable-row hidden">
			<? endif; ?>
				<?php echo elgg_view('input/date', array('name' => "timetable-date-$i", 
				'timestamp' => true, 'value' => (isset($timetable[$i]) ? $timetable[$i]['date'] : ''),
				'readonly' => true,));?>
				
				desde
				
				<?php echo elgg_view('input/dropdown', array('name' => "timetable-start-$i", 
				'options_values' => $minutes,
				'value' => (isset($timetable[$i]) ? $timetable[$i]['start'] : '')));?>
				
				hasta
				
				<?php echo elgg_view('input/dropdown', array('name' => "timetable-end-$i", 
				'options_values' => $minutes,
				'value' => (isset($timetable[$i]) ? $timetable[$i]['end'] : '')));?>
				<button type="button" onclick="removeLine(this);" class="elgg-button elgg-button-action">borrar</button>
			</div>
		<?php endfor; ?>
		
	</div>
	<div class="buttons" style="padding-top: 10px;">
		<a style="float:left" href="#basic-info" class="elgg-button">Atras</a>
		<a style="float:right" href="#prizes-info" class="elgg-button">Siguiente</a>
	</div>
</div>
<script type="text/javascript">
	timetableDummyRow = $('#timetable-dummy-row');
	//timetableDummyRow.removeAttr("id");
</script>

